//
//  MqInfoCompetitionTableViewController.m
//  Meiqi
//
//  Created by TwistedFate on 16/5/11.
//  Copyright © 2016年 KFC. All rights reserved.
//

#import "MqInfoCompetitionTableViewController.h"
#import "MqInfoListTableViewCell.h"
#import "MqInfoListModel.h"
#import "MqInfoWebViewController.h"
@interface MqInfoCompetitionTableViewController ()

@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation MqInfoCompetitionTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dataArray = [NSMutableArray array];
    
    [self dataProcess];
    self.tableView.rowHeight = 80 * kHeightBase;
    [self.tableView registerClass:[MqInfoListTableViewCell class] forCellReuseIdentifier:@"CompetitionCell"];
}

- (void)dataProcess{
    
    [PKRequestManager requestWithUrlString:@"http://www.biketo.com/app.php?m=client&a=render&showType=newsList&page=1&time=1462947111226&classid=88" parDic:nil Method:GET finish:^(NSData *data) {
        
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
        
//        NSLog(@"dic = %@", dic);
        
        NSArray *listAray = dic[@"list"];
        
        for (NSDictionary *dic in listAray) {
            
            MqInfoListModel *model = [[MqInfoListModel alloc] init];
            
            [model setValuesForKeysWithDictionary:dic];
            
            [_dataArray addObject:model];
            
        }
        
//        NSLog(@"DataArray = %@", _dataArray);
        [self.tableView reloadData];
        
    } error:^(NSError *error) {
        
        
        
        
    } path:nil];
    
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return _dataArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MqInfoListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CompetitionCell" forIndexPath:indexPath];
    
    MqInfoListModel *model = _dataArray[indexPath.row];
    
    cell.model = model;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MqInfoListModel *model = _dataArray[indexPath.row];
    
    MqInfoWebViewController *webView = [[MqInfoWebViewController alloc] init];
    webView.idsURL = [NSString stringWithFormat:@"http://www.biketo.com/app.php?m=client&a=render&&classid=%@&id=%@&userid=682480&version=1",model.classid, model.topicDetailID];
    
    // 标签的网址
    webView.tagListURL = [NSString stringWithFormat:@"http://www.biketo.com/app.php?m=client&a=getArticleTagOrTagListByType&type=tagList&id=%@",model.ids];
    
    // 作者信息的网址
    webView.authorInfoURL = [NSString stringWithFormat:@"http://www.biketo.com/app.php?m=client&a=getAuthorInfByType&type=authorInfo&classid=%@&id=%@",model.classid,model.ids];
    
    // 相关文章的网址
    webView.recommendListURL = [NSString stringWithFormat:@"http://www.biketo.com/app.php?m=client&a=render&version=1&platform=1&classid=%@&showType=recommendList",model.classid];
    // 评论的网址
    webView.commentURL = [NSString stringWithFormat:@"http://www.biketo.com/app.php?m=client&a=comment&methodType=getArticleCommentV1&access_token=&classid=%@&id=%@",model.classid,model.ids];
    
    
    [self.navigationController pushViewController:webView animated:YES];
    NSLog(@"%@",self.navigationController);
    
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
